<template>
  <div class="app">
    <router-view />
  </div>
</template>

<script type="text/ecmascript-6">
  const files = require.context('@src/source', true, /\.json$/)
  const chapter = {}
  files.keys().forEach(item => {
    let c = item.replace(/^\.\//, '').replace(/\/.+$/, '')
    let s = item.replace(/.+\//g, '').replace(/\.json$/, '')
    if (!chapter[c]) {
      chapter[c] = []
    } else {
      chapter[c].push(s)
    }
  })
  const arr = []
  for(let [key, value] of Object.entries(chapter)) {
    arr.push({[key]: value})
  }
  arr.sort((a,b)=> {
    return Object.keys(a)[0].split('.')[0] - Object.keys(b)[0].split('.')[0]
  })
  let tmp = {}
  arr.forEach(item => {
    tmp = Object.assign(tmp, item)
  })
  window.$chapter = tmp
  window.$files = files
export default {
  name: '',
}
</script>

<style lang="stylus" rel="stylesheet/stylus">
@import "~@design"
</style>
